<template>
	<view>
		<view class="user-box" @click="login">
			<view class="u-m-r-10">
				<u-avatar :src="userAvatarUrl" size="140"></u-avatar>
			</view>

			<view class="u-flex-1">
				<view class="user-name">{{vuexUserName || '请登录'}}</view>
				<view class="user-id">{{userId}}</view>
			</view>

			<view class="u-m-l-10 u-p-10" v-if="vuexUserName" @click.stop="logout">
				[登出]
			</view>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="rmb-circle" title="个人中心" @click="cellClick"></u-cell-item>
			</u-cell-group>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="star" title="收藏" @click="cellClick"></u-cell-item>
				<u-cell-item icon="photo" title="相册" @click="cellClick"></u-cell-item>
				<u-cell-item icon="coupon" title="卡券" @click="cellClick"></u-cell-item>
				<u-cell-item icon="heart" title="关注" @click="cellClick"></u-cell-item>
			</u-cell-group>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="setting" title="设置" @click="cellClick"></u-cell-item>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	import common from "@/common/common.js"
	export default {
		data() {
			return {
				pic: 'https://uviewui.com/common/logo.png',
				show: true
			}
		},
		computed: {
			userAvatarUrl() {
				return this.vuexUserInfo.id ? common.getRandomImgUrl() : "/static/user/avatar.png";
			},
			userId() {
				return this.vuexUserInfo.id ? `ID: ${this.vuexUserInfo.id}` : "";
			}
		},
		methods: {
			login() {
				if (this.vuexUserInfo.id) {
					uni.showToast({
						title: "用户积分界面"
					})
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			logout() {
				this.$u.vuex('vuexUserInfo', {});
				this.$u.vuex('vuexUserName', '');
				this.$u.vuex('vuexUserPassword', '');

				uni.removeStorageSync("USER-COOKIE");
			},
			cellClick(){
				this.$u.toast("功能开发中···");
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ededed;
	}

	.user-box {
		display: flex;
		align-items: center;
		padding: 30rpx 30rpx 30rpx 20rpx;
		background-color: #fff;
	}

	.user-name {
		font-size: 45rpx;
		padding-bottom: 20rpx;
	}

	.user-id {
		font-size: 28rpx;
	}
</style>
